package com.youxin.cpcenter.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.youxin.busfoundation.common.es.SearchComapny;
import com.youxin.busfoundation.common.es.bean.CompanyInfoBean;
import com.youxin.cpcenter.dao.TbConfigSearchCompanyMapper;
import com.youxin.cpcenter.model.TbConfigSearchCompany;
import com.youxin.cpcenter.service.ConfigSearchCompanyService;
import com.youxin.foundation.interfaces.Convert;

/**
 * 
 * @ClassName: ConfigSearchCompanyServiceImpl 
 * @Description: 查询默认企业 
 * @author yingde.cao
 * @date 2018年1月3日 上午11:22:06 
 *
 */
@Service("configSearchCompanyService")
public class ConfigSearchCompanyServiceImpl extends BaseServiceImpl implements ConfigSearchCompanyService {
	@Autowired
	private TbConfigSearchCompanyMapper tbConfigSearchCompanyMapper;

	public List<TbConfigSearchCompany> selectAllList() {
		return tbConfigSearchCompanyMapper.selectAllList();
	}
	
	@Override
	public <T> List<CompanyInfoBean> selectDefaultSearchList(int pageSize,Convert<CompanyInfoBean> convert) {
		try {
			List<TbConfigSearchCompany> configList=selectAllList();
			List<String> uids=configList.stream().map((item)->item.getUid()).collect(Collectors.toList());
			if(uids.size()>pageSize)
			{
				uids=uids.subList(0, pageSize);
			}
			List<CompanyInfoBean> companyList=new SearchComapny<CompanyInfoBean>(convert).queryCompanyInfosByUids(uids,CompanyInfoBean.class);
			return companyList;
		} catch (Exception e) {
			logger.error("selectDefaultSearchList", e);
			return new ArrayList<>();
		}
		
	}
}
